package net.halflite.mzkr.dto.user;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;

import net.halflite.mzkr.type.ImageExtensionType;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public class ImageDto implements Serializable {

	private static final long serialVersionUID = 1L;

	public BufferedImage image;
	
	public ImageExtensionType ext;
	
	public Date modified;
	
	public void setResponse(HttpServletResponse response) throws IOException {
		response.setContentType(ext.getContentType());
		response.setDateHeader("Last-Modified", modified.getTime());
		ImageIO.write(image, ext.getExt(), response.getOutputStream());
	}

	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}
}
